import { takeEvery, put } from 'redux-saga/effects'
import { GET_INIT_LIST } from './actionTypes'
import { initListAction } from './actionCreators'
import axios from 'axios'

function* getInitList() {
    try {
        const res = yield axios.get('/api/list.json');
        const action = initListAction(res.data)
       // console.log(action)
        yield put(action)  //  发送到reducer里面去
    } catch (e) {
        console.log('list.json请求数据失败')
    }

}

function* mySaga() {
    yield takeEvery(GET_INIT_LIST, getInitList)  // 当捕获到GET_INIT_LIST的action的时候，会执行getInitList的方法，也就是第二个参数的方法
}

export default mySaga;